package com.meixiang.adapter.service;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.meixiang.R;
import com.meixiang.activity.homes.service.ShowPictureActivity;
import com.meixiang.entity.services.ServiceDetail;
import com.meixiang.recyclerview.OnItemClick;
import com.meixiang.recyclerview.RecyclerAdapter;
import com.meixiang.util.DensityUtil;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * author:xiejingwen
 */
public class ServiceContentAdapter extends RecyclerAdapter<ServiceContentAdapter.ViewHolder> implements OnItemClick {
    private Context mContext;
    private ArrayList<ServiceDetail.StepListBean> stepListBean=new ArrayList<>();
    private Activity activity;
    public ServiceContentAdapter(Activity activity) {
        this.activity=activity;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        View view = LayoutInflater.from(mContext).inflate(R.layout.list_item_service_content, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tvNumber.setText(stepListBean.get(position).getStepSequence());
        holder.tvTitle.setText(stepListBean.get(position).getStepName());
        //设置间隔
        if (position > 0) {
            holder.itemView.setPadding(DensityUtil.dip2px(mContext, 10), 0, 0, 0);
        }
        Glide.with(activity).load(stepListBean.get(position).getStepImage()).error(R.drawable.image_default_gray_bg)
                .placeholder(R.drawable.image_default_gray_bg)
                .into(holder.img);
    }
    public void setStepListBean(ArrayList<ServiceDetail.StepListBean> stepListBean){
        this.stepListBean.clear();
        this.stepListBean.addAll(stepListBean);
        setOnItemClickListener(this);
        notifyDataSetChanged();
    }
    @Override
    public int getItemCount() {
        return stepListBean.size();
    }

    @Override
    public void onItemClick(View view, int position) {
        Intent intent=new Intent(mContext, ShowPictureActivity.class);
        intent.putParcelableArrayListExtra("data", stepListBean);
        intent.putExtra("position", position);
        mContext.startActivity(intent);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.img)
        ImageView img;
        @Bind(R.id.tv_number)
        TextView tvNumber;
        @Bind(R.id.tv_title)
        TextView tvTitle;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
